//
//  PopCategoryView.m
//  YTwallet
//
//  Created by ZhangLin on 2019/3/8.
//  Copyright © 2019年 hadrlog. All rights reserved.
//

#import "PopCategoryView.h"
#import <Masonry.h>
@implementation PopCategoryView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setupViews];
    }
    return self;
}

-(void)setupViews{
    
    self.backgroundColor = [UIColor whiteColor];
    
    
    self.resetBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.resetBtn.backgroundColor = [UIColor colorWithRed:233 / 255.0 green:236 / 255.0 blue:255 / 255.0 alpha:1];
    [self.resetBtn setTitle:@"重置" forState:(UIControlStateNormal)];
    [self.resetBtn setTitleColor:[UIColor colorWithRed:91 / 255.0 green:113 / 255.0 blue:255 / 255.0 alpha:1] forState:(UIControlStateNormal)];
    self.resetBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [self addSubview:self.resetBtn];
    [self.resetBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(44);
        make.width.equalTo(self).multipliedBy(0.5);
    }];
    
    self.confirmBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.confirmBtn.backgroundColor = [UIColor colorWithRed:91 / 255.0 green:113 / 255.0 blue:255 / 255.0 alpha:1];
    [self.confirmBtn setTitle:@"确定" forState:(UIControlStateNormal)];
    [self.confirmBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    self.confirmBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [self addSubview:self.confirmBtn];
    [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(44);
        make.width.equalTo(self).multipliedBy(0.5);
    }];
    
    self.lineView = [[UIView alloc] init];
    self.lineView.backgroundColor = [UIColor colorWithRed:229 / 255.0 green:229 / 255.0 blue:229 / 255.0 alpha:1];
    [self addSubview:self.lineView];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(1);
        make.top.equalTo(self);
    }];
    
    /*
    
    self.bigCategoryLab = [[UILabel alloc] init];
    self.bigCategoryLab.text = @"大类";
    self.bigCategoryLab.font = [UIFont boldSystemFontOfSize:16];
    self.bigCategoryLab.textColor = [UIColor colorWithRed:51 / 255.0 green:51 / 255.0 blue:51 / 255.0 alpha:1];
    [self addSubview:self.bigCategoryLab];
    [self.bigCategoryLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.equalTo(self.lineView.mas_bottom).offset(20);
    }];
    
    self.allCategoryBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.allCategoryBtn.backgroundColor = [UIColor colorWithRed:91 / 255.0 green:113 / 255.0 blue:255 / 255.0 alpha:1];
    self.allCategoryBtn.layer.cornerRadius = 18;
    [self.allCategoryBtn setTitle:@"全部" forState:(UIControlStateNormal)];
    [self.allCategoryBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    self.allCategoryBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [self addSubview:self.allCategoryBtn];
    [self.allCategoryBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bigCategoryLab.mas_bottom).offset(20);
        make.height.mas_equalTo(36);
    }];
    
    self.credictBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.credictBtn.backgroundColor = [UIColor colorWithRed:248 / 255.0 green:248 / 255.0 blue:248 / 255.0 alpha:1];
    self.credictBtn.layer.cornerRadius = 18;
    [self.credictBtn setTitle:@"信用卡收款" forState:(UIControlStateNormal)];
    [self.credictBtn setTitleColor:[UIColor colorWithRed:51 / 255.0 green:51 / 255.0 blue:51 / 255.0 alpha:1] forState:(UIControlStateNormal)];
    self.credictBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [self addSubview:self.credictBtn];
    [self.credictBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bigCategoryLab.mas_bottom).offset(20);
        make.height.mas_equalTo(36);
    }];
    
    self.swipeyBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.swipeyBtn.backgroundColor = [UIColor colorWithRed:248 / 255.0 green:248 / 255.0 blue:248 / 255.0 alpha:1];
    self.swipeyBtn.layer.cornerRadius = 18;
    [self.swipeyBtn setTitle:@"刷卡收款" forState:(UIControlStateNormal)];
    [self.swipeyBtn setTitleColor:[UIColor colorWithRed:51 / 255.0 green:51 / 255.0 blue:51 / 255.0 alpha:1] forState:(UIControlStateNormal)];
    self.swipeyBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [self addSubview:self.swipeyBtn];
    [self.swipeyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bigCategoryLab.mas_bottom).offset(20);
        make.height.mas_equalTo(36);
    }];
    
    
    
    //横向排列
    
    NSMutableArray *categoryArray = [NSMutableArray array];
    [categoryArray addObject:self.allCategoryBtn];
    [categoryArray addObject:self.credictBtn];
    [categoryArray addObject:self.swipeyBtn];
    
    [categoryArray mas_distributeViewsAlongAxis:(MASAxisTypeHorizontal) withFixedSpacing:15 leadSpacing:15 tailSpacing:15];
    
    
    
    self.withdrawBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.withdrawBtn.backgroundColor = [UIColor colorWithRed:248 / 255.0 green:248 / 255.0 blue:248 / 255.0 alpha:1];
    self.withdrawBtn.layer.cornerRadius = 18;
    [self.withdrawBtn setTitle:@"提现" forState:(UIControlStateNormal)];
    [self.withdrawBtn setTitleColor:[UIColor colorWithRed:51 / 255.0 green:51 / 255.0 blue:51 / 255.0 alpha:1] forState:(UIControlStateNormal)];
    self.withdrawBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [self addSubview:self.withdrawBtn];
    [self.withdrawBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.allCategoryBtn.mas_bottom).offset(15);
        make.height.mas_equalTo(36);
        make.centerX.equalTo(self.allCategoryBtn);
        make.width.equalTo(self.allCategoryBtn);
    }];
     
     
    

    self.swipeView = [[UIView alloc] init];
    [self addSubview:self.swipeView];
    [self.swipeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.equalTo(self.withdrawBtn.mas_bottom).offset(42);
        make.bottom.equalTo(self.resetBtn.mas_top);
    }];
    
    
    
    self.swipeCategoryLab = [[UILabel alloc] init];
    self.swipeCategoryLab.text = @"刷卡收款类";
    self.swipeCategoryLab.font = [UIFont boldSystemFontOfSize:16];
    self.swipeCategoryLab.textColor = [UIColor colorWithRed:51 / 255.0 green:51 / 255.0 blue:51 / 255.0 alpha:1];
    [self addSubview:self.swipeCategoryLab];
    [self.swipeCategoryLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(0);
    }];
     */
    
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    CGFloat with = ([UIScreen mainScreen].bounds.size.width - 60) / 3.0;
    CGFloat higth = 36;
    layout.itemSize = CGSizeMake(with, higth);
    NSLog(@"%f%f",with,higth);
    layout.minimumLineSpacing = 15;
    layout.minimumInteritemSpacing = 15;
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    
    
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:self.swipeView.bounds collectionViewLayout:layout];
    [self addSubview:self.collectionView];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineView.mas_bottom);
        make.bottom.equalTo(self.resetBtn.mas_top);
        make.left.equalTo(self).offset(15);
        make.right.equalTo(self).offset(-15);
    }];
}


@end
